﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WuDada.Trade.DataLoader.Utility
{
    public class GoogleStockDataConvertUtil
    {
        /// <summary>
        /// 將Google的DataDate轉成DateTime格式 EX: Aug 24, 2012
        /// </summary>
        /// <param name="dataTime"></param>
        /// <returns></returns>
        public static DateTime ToDateTime(string dataTime)
        {
            if (string.IsNullOrEmpty(dataTime))
            {
                throw new Exception(string.Format("Google Stock Date 格式不正確：{0}", dataTime));
            }

            //年
            string[] arrayDataTime = dataTime.Split(',');
            int year = int.Parse(arrayDataTime[1].Trim());

            //月日
            string[] arrayDate = arrayDataTime[0].Split(' ');
            MonthType monthType = (MonthType)Enum.Parse(typeof(MonthType), arrayDate[0]);
            int month = (int)monthType;
            int day = int.Parse(arrayDate[1].Trim());

            return new DateTime(year, month, day);
        }

        public enum MonthType
        {
            Jan = 1,
            Feb = 2,
            Mar = 3,
            Apr = 4,
            May = 5,
            Jun = 6,
            Jul = 7,
            Aug = 8,
            Sep = 9,
            Oct = 10,
            Nov = 11,
            Dec = 12
        }
    }

}
